<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" media="all">
</head>
<body>

<div class="layui-container">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" id="warehouseEditForm">
                <input type="hidden" name="id" value="${warehouse.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>仓库名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" autocomplete="off" class="layui-input" value="${warehouse.name}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>省份</label>
                    <div class="layui-input-block">
                        <select name="proId" data-type="1" data-click="10">
                            <option value="">请选择</option>
                            <c:forEach items="${addressList}" var="a">
                                <option value="${a.id}" ${a.id==warehouse.proId?'selected':''}>${a.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>城市</label>
                    <div class="layui-input-block">
                        <select name="cityId" class="city" data-type="2" data-click="20">
                            <c:forEach items="${cityList}" var="c">
                                <option value="${c.id}" ${c.id==warehouse.cityId?'selected':''}>${c.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>区域</label>
                    <div class="layui-input-block">
                        <select name="areaId" class="area">
                            <c:forEach items="${areaList}" var="a">
                                <option value="${a.id}" ${a.id==warehouse.areaId?'selected':''}>${a.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>详细地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="addressDetail" autocomplete="off" class="layui-input" value="${warehouse.addressDetail}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">&nbsp;</label>
                    <div class="layui-input-block">
                        <blockquote class="layui-elem-quote">
                            请选择准确的地址信息，系统将根据地址获取经纬度，<br>
                            如未获取到经纬度，该仓库将不可用。
                        </blockquote>
                    </div>
                </div>
            </form>
            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" onclick="FormSubmit('#warehouseEditForm','/warehouse/editWarehouse')">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form'], function(){
        var $ = layui.$,layer = layui.layer,form = layui.form;

        form.on('select',function (data) {
            var dom = data.elem;
            var type = $(dom).data('type');
            var clickType = $(dom).data('click');
            var id = data.value;
            if(type != null){
                $.ajax({
                    url: "/sys/queryAddressNoPage",
                    data: {"pid": id},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data.data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>'
                        });
                        if(type == 1){
                            $(".city").append(html);
                        }else if(type == 2){
                            $(".area").append(html);
                        }
                        form.render('select');
                    }
                });
            }
            switch (clickType) {
                case 10:
                    $(".city").empty();
                    $(".area").empty();
                    break;
                case 20:
                    $(".area").empty();
                    break;
            }
        });
    });
</script>
</body>
</html>